<?php
/**
 * File getXMLData.php
 * 
 * This function accepts 3 parameters: URI, username and password,
 * which it makes a new cURL object and connects to the URI. The XML
 * data from the URI is stored in a cURL object which is passed to
 * the getXMLData class which parses the object.
 */
/**
 * 
 */
include 'xmlToArray.php';

  /**
   * Function to instantiate a curl session. The curl object sets up options with the
   * curl_setopt function to initiate the request to the URL.  
   *
   * @param $URI is the name of the URI to access. 
   * @param $username  is the username for http authentication.
   * @param $password  is the password for the username for authentication.
   * @return $result  which contains whatever data the URI gives.
   */
  function retrieveXML($URI, $username, $password){
  	
  	// create a new curl resource
    $curlObject = curl_init();
    
    // set URL and other appropriate options
    curl_setopt($curlObject, CURLOPT_URL,$URI);
    curl_setopt($curlObject, CURLOPT_HEADER, 0);
    curl_setopt($curlObject, CURLOPT_USERPWD, $username.":".$password);
    curl_setopt($curlObject, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curlObject, CURLOPT_VERBOSE, 1);

    // grab URL and pass it to the browser
    $infoRetrieved = curl_exec($curlObject);
    echo curl_error($curlObject);

    // close curl resource, and free up system resources
    curl_close($curlObject);
    
    //creates a new xmlToArray class
    $XMLData = new xmlToArray(); 
    $xmlArray = $XMLData->parseXML($infoRetrieved);
    return $xmlArray;
  }  

?>    